<?php

class ErrorController extends Default_Library_Controller_Action
{

    public function init()
    {
        parent::init();

        // remove all CSS,JS
        $this->view->headLink()->setContainer(new Zend_View_Helper_Placeholder_Container());

        // Handling Previously Rendered Output
        $this->getResponse()->clearBody();

        // Set Layout
        $this->_helper->layout->setLayout('error');
    }

    public function errorAction()
    {
        $errors = $this->_getParam('error_handler');
        if (!empty($errors->type)) {
            switch ($errors->type) {
                case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
                case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
                case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
                    // 404 error -- controller or action not found
                    $this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');
                    $this->view->assign('errorMsg', 'Page not found!');
                    // ... get some output to display...
                    break;
                default:
                    $exception = $errors->exception;
                    $message = $exception->getMessage() . "\n" . $exception->getTraceAsString() . "\n";
                    $logger = Zend_Registry::get('logger');
                    $logger->log($message, Zend_Log::DEBUG);
                    $this->view->assign('errorMsg', 'Internal Server Error! Please contact Administrator.');
                    break;
            }
        } else {
            $this->view->assign('errorMsg', 'Internal Server Error! Please contact Administrator.');
        }
    }

}
